package com.drinkian.alipay.util;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.drinkian.alipay.config.ALiPayConfig;

public class ALiPayClientUtil {
    // 1.创建实例对象
    private static volatile AlipayClient instance;

    // 2.构造函数私有化
    private ALiPayClientUtil() {
    }

    // 3.暴露getInstance方法
    public static AlipayClient getInstance() {
        // 4.双检锁保证单例
        if (instance == null) {
            synchronized (ALiPayClientUtil.class) {
                if (instance == null) {
                    instance = new DefaultAlipayClient(
                            ALiPayConfig.gatewayUrl,
                            ALiPayConfig.app_id,
                            ALiPayConfig.merchant_private_key,
                            "json",
                            ALiPayConfig.charset,
                            ALiPayConfig.alipay_public_key,
                            ALiPayConfig.sign_type);
                }
            }
        }
        return instance;
    }
}
